package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.AuthorsActivity;
import com.zzk.lanouhn.myapplication1.modles.CollectSingleGood;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 用户头像适配器
 * Created by lanouhn on 16/9/16.
 */
public class UserIconAdapter extends RecyclerView.Adapter<UserIconAdapter.iconViewHolder> {

    private Context context;
    private List<CollectSingleGood.DataBean.LikesListBean> likesListBeen = new ArrayList<>();

    public UserIconAdapter(Context context, List<CollectSingleGood.DataBean.LikesListBean> likesListBeen) {
        this.context = context;
        this.likesListBeen = likesListBeen;
    }

    @Override
    public iconViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_icon_like_users, null);
        iconViewHolder holder = new iconViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(iconViewHolder holder, final int position) {
        Picasso.with(context).load(likesListBeen.get(position).getAvatar()).into(holder.iv_icon);
        holder.iv_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AuthorsActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("authorId", likesListBeen.get(position).getUser_id());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return likesListBeen.size() > 8 ? 8 : likesListBeen.size();
    }

    public class iconViewHolder extends RecyclerView.ViewHolder {
        private CircleImageView iv_icon;

        public iconViewHolder(View itemView) {
            super(itemView);
            iv_icon = (CircleImageView) itemView.findViewById(R.id.iv_icon_likes_user);
        }
    }
}
